package com.kang.service.impl;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.kang.dao.ShopMapper;
import com.kang.pojo.Shop;
import com.kang.service.ShopService;
import com.vonechina.entity.page.ShopPage;

/**
 * 店仓服务层实现类
 * 
 * @author zs614
 *
 */
@Service
public class ShopServiceImpl implements ShopService {
	/**
	 * 店仓持久层
	 */
	@Resource
	private ShopMapper sm;

	/**
	 * 分页查询店仓
	 * 
	 * @param shopPage
	 *            搜索条件实体类
	 * @return
	 */
	@Override
	public List<Shop> listShop(ShopPage shopPage) {

		shopPage.setRows(sm.countShop(shopPage));
		List<Shop> list = sm.listShop(shopPage);
		return list;
	}

	/**
	 * 查询全部店仓
	 * 
	 * @return
	 */
	@Override
	public List<Shop> listAllShop() {
		ShopPage shopPage = new ShopPage();
		shopPage.setPage(false);
		List<Shop> list = sm.listShop(shopPage);
		return list;
	}

	/**
	 * 删除店仓
	 * 
	 * @param shopid
	 *            店仓ID
	 * @return
	 */
	@Override
	public int deleteByPrimaryKey(Integer shopid) {

		return sm.deleteByPrimaryKey(shopid);
	}

	/**
	 * 新增店仓
	 * 
	 * @param record
	 *            店仓实体类
	 * @return
	 */
	@Override
	public int insert(Shop record) {

		return sm.insert(record);
	}

	/**
	 * 新增店仓
	 * 
	 * @param record
	 *            店仓实体类
	 * 
	 * @return
	 */
	@Override
	public int insertSelective(Shop record) {

		return sm.insertSelective(record);
	}

	/**
	 * 通过主键查询店仓
	 * 
	 * @param shopid
	 *            店仓OD
	 * @return
	 */
	@Override
	public Shop selectByPrimaryKey(Integer shopid) {

		return sm.selectByPrimaryKey(shopid);
	}

	/**
	 * 更新店仓
	 * 
	 * @param record
	 *            店仓实体类
	 * @return
	 */
	@Override
	public int updateByPrimaryKeySelective(Shop record) {

		return sm.updateByPrimaryKeySelective(record);
	}

	/**
	 * 更新店仓
	 * 
	 * @param record
	 *            店仓实体类
	 * @return
	 */
	@Override
	public int updateByPrimaryKey(Shop record) {

		return sm.updateByPrimaryKey(record);
	}

	/**
	 * 生成店仓编号
	 * 
	 * @return
	 */
	@Override
	public String generatoCode() {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
		String text = sdf.format(new Date()) + "0001";
		Long no = Long.parseLong(text);
		String max = sm.selectMaxCode();
		Long l = 0l;
		if (max != null) {
			l = Long.parseLong(max.replaceAll("[a-zA-Z]", ""));
		}
		if (l >= no) {
			no = l + 1;
		}
		return "DC" + no;
	}
}
